package sensors.virtualSensors;

import robots.OwnGhost;
import sensors.Pilot;
import simulation.Simulator;

public class VirtualPilot extends Pilot {
	private Randomizer randomizer;
	/**
	 * 
	 * @param ghost
	 * @param sim
	 * @param randomValues bepaalt of je randomwaardes wilt toevoegen aan je pilot
	 */
	public VirtualPilot(OwnGhost ghost, Simulator sim, boolean randomValues) {
		super(ghost, sim);
		if(randomValues){
			randomizer = new Randomizer();
		}
	}
	public VirtualPilot(OwnGhost ghost, Simulator sim){
		this(ghost, sim, false);
	}

	@Override
	public void simulateTravel(int distance) {
		if(randomizer != null)
			distance = randomizer.travelRandom(distance);
		super.simulateTravel(distance);

	}

	@Override
	public void simulateRotation(int angle) {
		if(randomizer != null)
			angle = randomizer.rotateRandom(angle);
		super.simulateRotation(angle);

	}

	@Override
	public void setSpeed(int speed) {
		super.speed=speed;
	}

	@Override
	public int travelWithUltrasonicInterrupt(int distance, int margin) {
		int countdown = distance;
		while(ghost.getUltrasonicSensor().getDistance()>margin && countdown>0) {
			super.simulateTravel(5);
			countdown-=5;
		}
//		System.out.println("inacc in ultrasonic:"+simulator.getGhostLocations().get(ghost));
//		System.out.println("inacc in ultrasonic rot:"+simulator.getGhostRotations().get(ghost));
		return distance-countdown;
	}
	
	

}
